package Controllers;

import Connection.User;
import SwingComponents.PrincipalPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PrincipalController implements ActionListener {

    private Application application;
    private PrincipalPanel principalPanel;
    private User user;

    public PrincipalController(Application application) {
        this.application = application;
        initPrincipalPanel();

        user = new User(null, null, null, null, null);
    }

    private void initPrincipalPanel() {
        principalPanel = new PrincipalPanel(this);
        principalPanel.setVisible(true);
        application.add(principalPanel);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("Play")) {
            principalPanel.setVisible(false);
            ArkanoidController arkanoidController = new ArkanoidController(this, user);
            arkanoidController.execute();
        } else if (e.getActionCommand().equals("Select World")) {
            principalPanel.setVisible(false);
            SelectWorldController selectWorldController = new SelectWorldController(this, user);
        } else if (e.getActionCommand().equals("Create World")) {
            principalPanel.setVisible(false);
            CreateWorldController createWorldController = new CreateWorldController(this);
        } else if (e.getActionCommand().equals("Options")) {
        } else if (e.getActionCommand().equals("Log in")) {
            UserLoginController userLoginController = new UserLoginController(this);
            userLoginController.execute();
        } else if (e.getActionCommand().equals("Register")) {
            UserRegisterController userRegisterController = new UserRegisterController(this);
            userRegisterController.execute();
        }
    }

    public Application getApplication() {
        return application;
    }

    public PrincipalPanel getPrincipalPanel() {
        return principalPanel;
    }

    public User getUser() {
        return user;
    }
    
    public void setUser(User user){
        this.user = user;
    }
}
